home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / zcpp_jae.zip / MEMBER.C < prev    next >
C/C++ Source or Header  |  1990-07-06  |  1KB  |  65 lines

  1. /*
  2.  
  3.  
  4.  Copyright (C) 1990 Texas Instruments Incorporated.
  5.  
  6.  Permission is granted to any individual or institution to use, copy, modify,
  7.  and distribute this software, provided that this complete copyright and
  8.  permission notice is maintained, intact, in all copies and supporting
  9.  documentation.
  10.  
  11.  Texas Instruments Incorporated provides this software "as is" without
  12.  express or implied warranty.
  13.  
  14.  
  15.  *
  16.  * Edit history
  17.  * Created: LGO 30-Mar-89 -- Initial design and implementation.
  18.  *
  19.  * MEMBER defmacro
  20.  *
  21.  * CPP defmacro for doing symbolic comparisions
  22.  * The input looks like MEMBER(arg1, arg2, ..., argn)
  23.  * The output is "1" when arg1 is the same as one of the other args, else "0".
  24.  *
  25.  */
  26.  
  27. #include "defmacio.h"
  28.  
  29. #define BSIZE 512
  30.  
  31. member(argc, argv)
  32.    int argc;
  33.    char** argv;
  34. {
  35.   char c;
  36.   char macname[BSIZE];
  37.   char* arg1;
  38.   char* arg2;
  39.  
  40.   if(copytoken(macname) == NULL)      /* Skip macro name */
  41.     return(1);
  42.  
  43.   c = skip_blanks();
  44.   if(c != '(') {
  45.     fprintf(stderr, "%s: Can't find argument list\n", macname);
  46.     return 1;
  47.   }
  48.  
  49.   arg1 = scan_token(",)");
  50.   getchar();
  51.   do {
  52.     arg2 = scan_token(",)");
  53.     if(strcmp(arg1, arg2) == 0) {
  54.       putchar('1');
  55.       goto exit;
  56.     }
  57.     free(arg2);
  58.   } while (getchar() != ')');
  59.   putchar('0');
  60.  exit:
  61.   free(arg1);
  62.   free(arg2);
  63.   return 0;
  64. }
  65.